<template>
    <div>
        <el-table  :data="filelsdtaTrue"  border  @cell-dblclick="showrecoderFiles"  :empty-text="showemptytext">
            <el-table-column  width="120" label="标识" align="center">
                <template slot-scope="scope">
                    <img class="default-image" :src="$store.state.images.wujiaoxing" style="width：45px;height:45px;"> 
                </template> 
            </el-table-column>
            <template v-if="showchild==true">
                <el-table-column   label="标识"  align="center" width="120"  >
                    <template slot="header" slot-scope="scope" >
                        <el-popover placement="right"  trigger="hover">
                            <div>
                                <el-select v-model="childtype" clearable placeholder="请选择" @change="changetype">
                                    <el-option v-for="item in childtypes" :label='item.name' :value='item.name' :key="item.nam"></el-option>
                                </el-select>
                            </div>
                            <el-button slot="reference">类型</el-button>
                        </el-popover>
                    </template>
                    <template slot-scope="scope">
                        <div>{{childtype}}</div>
                    </template>
                </el-table-column>
            </template>
            <el-table-column type="index" label="序号" width="80" align="center" :index="indexbf"></el-table-column>
            <el-table-column prop="name" width="630" label="名称" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column prop="time" width="180" label="时间" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
            <el-table-column align="right">
                <template slot="header" slot-scope="scope">
                    <el-button  size="mini"  @click="serchrecorde">查询</el-button>
                    <el-button  size="mini"  @click="addrecorde" v-show="showAdd">新增</el-button>
                </template>
                <template slot-scope="scope">
                    <el-dropdown trigger="click" @command="recordeCommand" v-show="showAdd">
                        <span class="el-dropdown-link">操作<i class="el-icon-caret-bottom el-icon--right"></i></span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item class="clearfix" :command="{data:scope.row,typed:'delete'}">删除</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>
        <pagination @changed="showDataTrue" :recoder="filerecordes"> </pagination>
        <zzlihuiadd ref='zzlihuiadd' v-on:editResult="serchrecorde"></zzlihuiadd>
    </div>
</template>
<script>
    import {mapActions} from 'vuex';
    export default {
        data: () => ({
            showAdd:false,//显示添加的按钮,
            typeA:'',
            typeB:'',
            typeBB:'',
            samedwdzb:false,//用于一些项目及其文件为全局统一  不再按照各党委党支部配置
            filerecordes:[],
            filelsdtaTrue:[],
            offset:0,
            //第一个表格
            currentPageA:1,
            pageSizeA:10,
            totalA:0,
            default_emptytext:"请点击右侧查询记录",
            showemptytext:'',

            showchild:false,
            childtype:'',
            childtypes:[],
        }),
        mounted() {
            if(this.GetUser()==false){
                this.$router.push("/");
            }
            this.GetActiveDwId_DzbId();
            if (this.$store.state.Dw_DzbID.dwid==-1) {
                if(this.$store.state.user.operation==0){
                    this.showAdd=true;
                }
            }
            else if(this.$store.state.Dw_DzbID.dzbid==-1){
                if(this.$store.state.user.operation<=1){
                    this.showAdd=true;
                }
            }
            else if(this.$store.state.Dw_DzbID.dzbid>-1 && this.$store.state.Dw_DzbID.dzbid>-1){
                if(this.$store.state.user.operation<=2){
                    this.showAdd=true;
                }
            }
        },
        watch: {
            "typeB": {
                handler(n) {
                    let backto='';
                    if(this.typeB=="三会一课"){
                        this.childtypes=[
                            {name:'支部委员会'},
                            {name:'支部党员大会'},
                            {name:'党小组会'},
                            {name:'党课'}
                        ];
                        this.showchild=true;
                        this.childtype=this.childtypes[0].name;
                        backto=this.childtype;
                        
                    }
                    else if(this.typeB=="组织生活会"){
                        this.childtypes=[
                            {name:'民主评议班子'},
                            {name:'民主评议党员'}
                        ];
                        this.showchild=true;
                        this.childtype=this.childtypes[0].name;
                        backto=this.childtype;
                    }
                    else{
                        this.childtypes=[];
                        this.childtype="";
                        this.showchild=false;
                    }
                    this.typeBB=this.typeB;
                    if(this.childtype!=""){
                        this.typeBB=this.typeBB+'-'+this.childtype;
                    } 
                    this.$emit('changetypeChild',backto);
                },
                deep: true
            }, 
            
        },
        components: {
            zzlihuiadd: function(resolve) {require(["./add.vue"], resolve);},
        },
        methods: {
            ...mapActions(['GetUser','GetActiveDwId_DzbId']),
            changetype(type){
                this.typeBB=this.typeB;
                if(this.childtype!=""){
                    this.typeBB=this.typeBB+'-'+this.childtype;
                } 
                this.$emit('changetypeChild',type);
                this.serchrecorde();
            },
            serchrecorde(){
                let _this=this;
                this.filerecordes=[];
                this.$emit('gettab',this.typeBB);
                return new Promise(function (resolveroot, rejectroot) {
                    let postdata={
                        type:"getrecoder",
                    }
                    if(_this.samedwdzb==true){
                        postdata.split=JSON.stringify({
                            dwid:-1,
                            dzbid:-1,
                            typeA:_this.typeA,
                            typeB:_this.typeBB,
                        })
                    }
                    else{
                        postdata.split=JSON.stringify({
                            dwid:_this.$store.state.Dw_DzbID.dwid,
                            dzbid:_this.$store.state.Dw_DzbID.dzbid,
                            typeA:_this.typeA,
                            typeB:_this.typeBB,
                        })
                    }
                    _this.$Common.AjaxPost(postdata,true)
                    .then(function(e){
                        if(e.FileRecods.length==0){
                            _this.showemptytext='没有找到记录';
                            setTimeout(() => {
                                _this.showemptytext=_this.default_emptytext;
                            }, 1000);
                        }
                        else{
                            _this.filerecordes=e.FileRecods;
                        }
                        _this.$emit('serchrecorde',e.FileRecods);
                        resolveroot(true);
                    });
                });
            },
            addrecorde()
            {
                this.$refs.zzlihuiadd.$data.detailsVisible = true;
                this.$refs.zzlihuiadd.$data.needZk = false;
                this.$refs.zzlihuiadd.$data.title = '新增'+this.typeB;
                this.$refs.zzlihuiadd.$data.rowdata.typea=this.typeA;
                let typeBB=this.typeB;
                if(this.childtype!=""){
                    typeBB=typeBB+'-'+this.childtype;
                } 
                this.$refs.zzlihuiadd.$data.rowdata.typeb=typeBB;
            },
            recordeCommand(value)
            {
                let row=value.data;
                let typed=value.typed;
                let _this=this;
                if(typed=="delete"){
                    let postdata={
                        type:"deleterecoder",
                        split:JSON.stringify({
                            recoder:row.recoder,
                        })
                    }
                    this.$Common.AjaxPost(postdata,true)
                    .then(function(e){
                         _this.$message('删除成功');
                         _this.serchrecorde();
                    })
                }
            },
            showrecoderFiles(row, column, cell, event){ //双击获取指定的文件
                this.$emit('serchfile',row.recoder,row.time);
            },
            showDataTrue(showrecoders,offset){
                this.filelsdtaTrue=showrecoders;
                this.offset=offset;
            },
            indexbf(index){return index+this.offset+1;},
        }
    }
</script>
<style>
</style>